package org.lztvn.elearning.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;



import javax.persistence.Query;
import org.lztvn.elearning.entities.News;

public class NewsDaoImpl implements INewsDAO {
	@PersistenceContext
	private EntityManager em;
	@Override
	public Long addNews(News n) {
		em.persist(n);
		return n.getId();
	}

	@Override
	public void deleteNews(Long idn) {
		News n = em.find(News.class, idn);
		em.remove(n);
		
	}

	@Override
	public void modifierNews(News n) {
		em.merge(n);
	}

	@Override
	public News getNews(Long idn) {
		return em.find(News.class, idn);
	}

	@Override
	public List<News> listNews() {
		Query req = em.createQuery("select n from News n");
		return req.getResultList();
	}

}
